//============================================================================
// Name        : Fraction.cpp
// Author      : Thada Pipatcharoenkij 49270325
// Description : Fraction, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

/**
 * Fraction class to store numerator and denominator
 */
class Fraction {
public:
	Fraction(double, double);
	virtual ~Fraction();
	double getNumerator();
	double getDenominator();
	void setNumerator(double);
	void setDenominator(double);
	void showLowestTerm();
	void toString();

private:
	int gcd(int, int);
	/** Numerator */
	double num;
	/** Denominator */
	double deno;
};

/**
 * Constructor to create fraction by set numerator and denominator
 * @param n real value for numerator
 * @param d real value for denominator
 */
Fraction::Fraction(double n, double d){
	num = n;
	deno = d;
}

/**
 * To get value of denominator
 * @return denominator real number
 */
double Fraction::getDenominator(){
	return deno;
}

/**
 * To get value of numerator
 * @return numerator real number
 */
double Fraction::getNumerator(){
	return num;
}

/**
 * To set denominator
 * @param newD real number
 */
void Fraction::setDenominator(double newD){
	deno = newD;
}

/**
 * To set numerator
 * @param newN real number
 */
void Fraction::setNumerator(double newN){
	num = newN;
}

/**
 * To find great common divisor value of 2 numbers
 * @param a first number
 * @param b second number
 * @return great common divisor value
 */
int Fraction::gcd(int a, int b){
	if (a == 0){
		return b;
	}
	while (b != 0){
		if (a > b){
			a = a - b;
		}
		else {
			b = b - a;
		}
	}
	return a;
}

/**
 * To display lowest term of both numerator and denominator
 */
void Fraction::showLowestTerm(){
	int gcdValue = gcd((int)num, (int)deno);
	cout << num / gcdValue << "/" << deno / gcdValue << endl;
}

/**
 * To display fraction
 */
void Fraction::toString(){
	cout << num << "/" << deno << endl;
}

/**
 * main method to test Fraction program
 */
int main() {
	Fraction f(52,39); //create fraction of 52/39
	f.toString();
	f.showLowestTerm();
	f.setNumerator(100.0); //set new value of numerator
	f.setDenominator(30.0); //set new value of denominator
	f.toString();
	f.showLowestTerm();
	return 0;
}
